#!/bin/bash
#
#  btchdd The BitcoinHD Core server.
#
#
# chkconfig: 345 80 20
# description: btchdd
# processname: btchdd
#

# Source function library.
. /etc/init.d/functions

# you can override defaults in /etc/sysconfig/bccod, see below
if [ -f /etc/sysconfig/btchdd ]; then
        . /etc/sysconfig/btchdd
fi

RETVAL=0

prog=btchdd
# you can override the lockfile via BTCHDD_LOCKFILE in /etc/sysconfig/btchdd
lockfile=${BTCHDD_LOCKFILE-/var/lock/subsys/btchdd}

# btchdd defaults to /usr/bin/btchdd, override with BTCHDD_BIN
btchdd=${BTCHDD_BIN-/usr/bin/btchdd}

# btchdd opts default to -disablewallet, override with BTCHDD_OPTS
btchdd_opts=${BTCHDD_OPTS--disablewallet}

start() {
    echo -n $"Starting $prog: "
    daemon $DAEMONOPTS $btchdd $btchdd_opts
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $prog
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: service $prog {start|stop|status|restart}"
        exit 1
        ;;
esac
